package org.ruslan.kolobok.model;

import com.badlogic.gdx.math.Vector3;

public class LevelObject<T extends Type> {
	protected final T type;
	private final Vector3 position;
	private boolean active;
	protected State state;
	private float stateTime;
	private final RenderType renderType;
	
	public enum RenderType {
		ATLAS, STILL
	}
	
	public LevelObject(T type) {
		this.type = type;
		String graphics = type.getGraphics();
		if (graphics.endsWith(".png")) {
			renderType = RenderType.STILL;
		}
		else {
			renderType = RenderType.ATLAS;
		}
		position = new Vector3();
	}
	
	public T getType() {
		return type;
	}
	
	public String getGraphics() {
		return type.getGraphics();
	}

	public Vector3 getPosition() {
		return position;
	}
	
	public float getWidth() {
		return type.getWidth();
	}

	public float getHeight() {
		return type.getHeight();
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	public float getStateTime() {
		return stateTime;
	}

	public void setStateTime(float stateTime) {
		this.stateTime = stateTime;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		if (state != this.state) {
			stateTime = 0;
			this.state = state;
		}
	}
	
	public RenderType getRenderType() {
		return renderType;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("LevelObject [type=");
		builder.append(type);
		builder.append(", position=");
		builder.append(position);
		builder.append(", active=");
		builder.append(active);
		builder.append(", state=");
		builder.append(state);
		builder.append(", stateTime=");
		builder.append(stateTime);
		builder.append("]");
		return builder.toString();
	}
}
